<template>
  <div>
    <div class="wrapper">
        <FormPanel ref="formPanel" :list="formList" :cols="3" labelWidth="110" :isSubmitBtn="false" />
        <div style="margin-bottom: 1rem;"></div>
        <BreakSpace label="操作历史" :containerStyle="{ marginBottom: '10px' }" />
        <FilterTable
          ref="table"
          :columns="columns"
          :dataSource="dataList"
          :onColumnsChange="columns => (this.columns = columns)"
          :onRowSelectChange="columns => (this.selectColumns = columns)"
          :isSelectColumn="false"
          :isToperInfo="false"
          :isColumnFilter="false" 
          :height="172"
          style="margin-bottom:20px;"
        /> 
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
        <el-button @click="closeDialog">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getHistory } from '@/api/serviceass/batteryAlarm/batteryAlarmManage';
export default {
  name: 'rescueEditDialog',
  props: {
    formData: {
      type: Object,
      default: () => ({})
    }
  },
  mixins: [dictionary],
  data() {
    return {
      formList: this.createFormList(),
      columns: this.createTableColumns(),
      fetchParams: {},
      dataList: [],
      formData:{} 
    };
  },
  async created(){
    this.formList.forEach(x => {
      x.initialValue = this.formData[x.fieldName];
    });
    const res = await getHistory({ bwId: this.formData.bwId });
    this.dataList = res.data
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '报警信息'
        },
        {
          type: 'INPUT',
          label: '消息编号',
          fieldName: 'code',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '报警名称',
          fieldName: 'alarmName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '报警级别',
          fieldName: 'alarmLevel',
          disabled: true,
          itemList: [
            {text: "一级报警",value: 1},
            {text: "二级报警",value: 2},
            {text: "三级报警",value: 3}
            ],
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '报警类别',
          fieldName: 'type',
          disabled: true,
          itemList: [
            {text: "国际报警",value: 1},
            {text: "自定义报警",value: 2},
            {text: "阈值报警",value: 3},
            {text: "预警",value: 4}
            ],
        },
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'ownerName',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车主联系电话',
          fieldName: 'contactorMobile',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '使用人姓名',
          fieldName: 'userName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系方式',
          fieldName: 'userTel',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经度',
          fieldName: 'eastLongitude',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '纬度',
          fieldName: 'northLatitude',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '省份',
          fieldName: 'province',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '城市',
          fieldName: 'city',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '区县',
          fieldName: 'region',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '具体地址',
          fieldName: 'address',
          initialValue: '',
          disabled: true,
          selfCols: 3
        },
        {
          type: 'INPUT',
          label: '分析意见',
          fieldName: 'analyzeNode',
          initialValue: '',
          selfCols: 3,
          disabled: true
        },
        {
          type: 'BREAK_SPACE',
          label: '处理信息'
        },
        {
          type: 'INPUT',
          label: '报警时间',
          fieldName: 'alarmTime',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '分派时间',
          fieldName: 'assignTime',
          initialValue: '',
          disabled: true,
          
        },
        {
          type: 'INPUT',
          label: '处理时间',
          fieldName: 'opAT',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '报警分类',
          fieldName: 'alarmClass',
          disabled: true,
          itemList: this.createDictList('5592'),
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'state',
          initialValue: '',
          disabled: true,
          itemList: this.createDictList('5566')
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件信息',
          fieldName: 'appendixAddress',
          disabled: true,
          initialValue: '',
          selfCols: 3
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'opNote',
          selfCols: 3,
          initialValue: '',
          maxlength: 300,
          disabled: true
        },
      ];
    },
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作后状态',
          dataIndex: 'opState',
          sorter: true,
          dictItems: this.createDictList('5566')
        },
        {
          title: '操作人',
          dataIndex: 'opBy',
          sorter: true,
        },
        {
          title: '操作时间',
          dataIndex: 'opAt',
          sorter: true,
        },
        {
          title: '操作说明',
          dataIndex: 'opNote',
          sorter: true,
        },
      ];
    },
  }
};
</script>
